arc != uname -m | grep -e x86_64 -e amd64 | wc -c
.if( $(arc) == 0 )
.error invalid architecture
.endif

TARG = meliy mkhisr

#
ASM = yasm
CC  = gcc46
FC  = gfortran46
LD  = gfortran46
AR = ar
#
AFLAGS = -f elf64 -a x86 -m amd64
CFLAGS = -c -Wall -std=gnu99
FFLAGS = -m64 -msse -msse2 -msse3 -m3dnow -mfpmath=sse \
	-fdefault-real-8 -fdefault-integer-8 -fno-range-check \
	-pipe -fcray-pointer -fbackslash -masm=att\
	-c -Wall -cpp -Wno-conversion
OMPFLAGS = -fopenmp
LDFLAGS = -m64  -lkvm -lgomp -lpthread
ARFLAGS = -rc

#
PREFIX?=/usr/local/pet
LIBDIR= ${PREFIX}/lib
BINDIR= ${PREFIX}/bin
MANDIR= ${PREFIX}/man

#
.ifdef _DEBUG_
AFLAGS += -g stabs 
CFLAGS += -g
FFLAGS += -g
.else
FFLAGS += -s -fomit-frame-pointer -O3 
.endif

#
LDEP = 

#
MDEP = 

#
MELIYOBJ = ground_control.o oct_pet.o projectors.o molsem.o

#
.PHONY: clean all install

.SUFFIXES:
.SUFFIXES: .o .s .f90 .mod .c

all: $(TARG)

.c.o:
	$(CC) $(CFLAGS) $<

.f90.o:
	$(FC) $(FFLAGS) $<

.F90.o:
	$(FC) $(FFLAGS) $<

.f90.mod:
	$(FC) $(FFLAGS) $<

.s.o:
	$(ASM) $(AFLAGS) $<

oct_pet.o:	oct_pet.f90
	$(FC) $(FFLAGS)  $(OMPFLAGS) $<

projectors.o:	projectors.f90
	$(FC) $(FFLAGS)  $(OMPFLAGS) $<

libmeliy.a:	autyF.o libcf.o sutyA.o sutyF.o dutyF.o 
	$(AR) $(ARFLAGS) $@ $(.ALLSRC)

ground_control.o: meliy.f90 ground_control.f90
	$(FC) $(FFLAGS) ground_control.f90

meliy:	libmeliy.a $(MELIYOBJ)
	./puttime meliy.f90
	$(LD) $(LDFLAGS) $(MELIYOBJ) libmeliy.a -o $@

mkhisr:	libmeliy.a mkhisr.o
	$(LD) $(LDFLAGS) mkhisr.o libmeliy.a -o $@

install: $(TARG)
	mkdir -p $(BINDIR)
	cp -pRf $(TARG) scripts/* $(BINDIR)

clean:
	rm -f *.o *.*~ *.core *.mod *.a $(TARG)
